package com.hz.web.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;

public class HttpPrintHelper {
	
	private final static String type = "application/json;charset=UTF-8";
	
	public static JSONObject result(boolean re,String code,JSONObject info,String reason){
		String strInfo = "";
		if(info!=null) {
			try {
				strInfo=info.toJSONString();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		JSONObject jo = new JSONObject();
		jo.put("result", re);//调用状态
		jo.put("resultCode", code);
		jo.put("resultInfo", (info == null) ? "": "" + strInfo + "");//返回值
		jo.put("reason", reason);//原因
		return jo;
	}
	
	public static void outPrint(HttpServletResponse response,JSONObject jo){
		try {
			response.setContentType(type);
			
			System.out.println("返回参数：：：：：：" + jo.toJSONString());
			PrintWriter out = response.getWriter();
			out.println(jo.toJSONString());
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
